package com.realone.packman.codec.decoder;

import com.realone.packman.codec.decoder.vo.BmsDecoderDataVo14;
import com.realone.packman.codec.exception.BmsDecoderException;
import com.realone.packman.codec.vo.CellTemperature;

import java.nio.ByteBuffer;

/**
 * 获取BMS温度 解码
 *
 * @author hugx
 * @create 2018-09-14 13:16
 */
public class BmsDecoder14 extends BmsDecoder<BmsDecoderDataVo14> implements BmsDecoderStrategy {

    public BmsDecoder14(Integer classType) {
        this.classType = classType;
    }

    @Override
    public BmsDecoderDataVo14 decoderBody(ByteBuffer bb) {
        if (bb == null) {
            throw new BmsDecoderException(new NullPointerException());
        }

        BmsDecoderDataVo14 result = new BmsDecoderDataVo14(this.classType);

        /* 解析6个温度探测点 */
        decoderCellTemperature(bb,result);

        return result;
    }

    private void decoderCellTemperature(ByteBuffer bb, BmsDecoderDataVo14 bmsDecoderDataVo14) {
        CellTemperature temperature=bmsDecoderDataVo14.getCellTemperature();
        if(temperature == null){
            temperature=new CellTemperature();
            bmsDecoderDataVo14.setCellTemperature(temperature);
        }

        temperature.setOne((char) bb.get());
        temperature.setTwo((char) bb.get());
        temperature.setThree((char) bb.get());
        temperature.setFour((char) bb.get());
       //TODO 暂时注掉  temperature.setFive((char) bb.get());
        temperature.setSix((char) bb.get());
    }




}
